﻿using DevExpress.XtraEditors;
using SX_MesProject.Dtos;
using SX_MesProject.Dtos.SchedulingDTO;
using SX_MesProject.Dtos.SchedulingTasksDTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SX_MesProject.SchedulingTasks
{
    public partial class SchedulingTasksAdd : DevExpress.XtraEditors.XtraForm
    {
        public delegate Task LoadData();
        public event LoadData OnLoadData;
        public SchedulingTasksAdd()
        {
            InitializeComponent();
        }

        private void SchedulingTasksAdd_Load(object sender, EventArgs e)
        {
            ScheduType();
        }

        private void textEdit1_EditValueChanged(object sender, EventArgs e)
        {
            SchedulingTasksDTO schedulingTasksDTO = new SchedulingTasksDTO();
            schedulingTasksDTO.dispatch_number = "132456";


        }


        private async void ScheduType()
        {
            var refult = await HttpClientHelper.RequestUrl<string, ResponseDto<List<SchedulingType>>>("https://localhost:44556/", "GetSchedulingType", HttpClientHelper.MethodType.GET);
            this.lookUpEdit1.Properties.DataSource = refult.Data;
            lookUpEdit1.Properties.DisplayMember = "scheduling_type_name";
            lookUpEdit1.Properties.ValueMember = "scheduling_type_id";


        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Add();
        }

        private async void Add()
        {
            SchedulingAddDTO schedulingTasksDTO = new SchedulingAddDTO();
            schedulingTasksDTO.dispatch_number =textEdit1.Text;
            schedulingTasksDTO.scheduling_type_id= (int)lookUpEdit1.EditValue;
            schedulingTasksDTO.scheduling_information = memoEdit1.Text;
            schedulingTasksDTO.LocationNo = textEdit2.Text;
            schedulingTasksDTO.moves_number = Convert.ToInt32(spinEdit1.Text);
            schedulingTasksDTO.priority = Convert.ToInt32(spinEdit2.Text);
            var list = await HttpClientHelper.RequestUrl<SchedulingAddDTO, ResponseDto<SchedulingAddDTO>>("https://localhost:44556/", "AddSchedulingTasks", HttpClientHelper.MethodType.POST, schedulingTasksDTO);
            if (list.Code == 200)
            {
                MessageBox.Show("添加成功!");
                OnLoadData?.Invoke();
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
            }


        }

    }
}